
#include "wtp_state.h"

wtp_state_t wtp_state_image_data()
{

	EchoInterval = 0;
	
	invoke Image Data Request message;
	
	if(receiver Image Data Response message) {
		Image Data Request;
	}
	
	if(ImageDataStartTimer expires) {
		return WTP_STATE_RESET;
	}
	
	if(DTLSAborted || DTLSReassemblyFailure || DTLSPeerDisconnect) {
		DTLSSessionDelete;
	}
	
	return WTP_STATE_DATA_CHECK;
}

wtp_state_t wtp_state_configure()
{

	invoke Configuration Status Request message;
	
	if(Configuration Status Response message has error) {
		return WTP_STATE_RESET;
	}
	
	if(DTLSAborted || DTLSReassemblyFailure || DTLSPeerDisconnect) {
		return WTP_STATE_DTLS_TD;
	}
	
	if(Configuration Status Response message has received) {
		Change State Event Request message;
		return WTP_STATE_DATA_CHECK;
		
	}
	
	return WTP_STATE_IMAGE_DATA;
}

wtp_state_t wtp_state_data_check()
{
	if(!Change State Event Response message) {
		if(RetransmitCount >= MaxRetransmit) {
			DTLSSessionDelete;
		}
	}
	
	initiates the data channel;
	
	DataChannelKeepAlive = 0;
	send Data Channel Keep-Alive packet;
	
	EchoInterval = 0;
	DataChannelDeadInterval = 0;
	
	
	return WTP_STATE_RUN;
}
